package com.jf.ai.service;

import jakarta.annotation.Resource;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.model.ChatModel;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created with IntelliJ IDEA
 * Description:
 * User:22954
 * Date:2025-06-04
 * Time:14:11
 */
@RestController
public class WebController {
    @Resource
    private ChatModel chatModel;
    private final ChatClient chatClient;
    public WebController(ChatClient.Builder chatClientBuilder) {
        this.chatClient = chatClientBuilder.build();
    }
    @GetMapping("/call")
    public String call(@RequestParam(value = "message", defaultValue = "你好") String message) {
        long in = System.currentTimeMillis();
        String response = chatModel.call(message);
        System.out.println("time: " + (System.currentTimeMillis() - in));
        return response;
    }
    @GetMapping("/chat")
    public String chat(@RequestParam(value = "message", defaultValue = "你好") String message) {
        long in = System.currentTimeMillis();
        String response = chatClient.prompt().user(message).call().content();
        System.out.println("time: " + (System.currentTimeMillis() - in));
        return response;
    }
}
